/**
 * @author mapeng
 * @version 2017-05-10
 */

(function(doc, win) {

	var pageVariables = {"shopId" : "" , "shop" : {} , "weixinAccount" : {} };

	$(doc).on("pageInit", "#weixinChangePage", function(e, pageId, $page, isBack , isForward) {
		if(isForward) return;
		if(isBack){
			handleBack();
			return;
		}
		
		initData4Page();
	});
	bindEvent4Page();

	function handleBack(){
		var params = CommonUtil.takeOutParamObject() || {};
		var operation = params.operation;

		if(operation == "branchSearch"){//支行搜索
			var contactLine = params.contactLine;
			var branchBankName = params.branchBankName;
			$("#weixinChangePage input[name='branchBank']").val(branchBankName);
			$("#weixinChangePage input[name='contactLine']").val(contactLine);

			listen4Submit();
		}

		params.operation = "";
		CommonUtil.injectParamObject(params);
	}

	//页面初始化
	function initData4Page(){

		var params = CommonUtil.takeOutParamObject() || {};
		pageVariables.shopId = params.shopId;	

		//查询门店
		CommonUtil.sendJsonpRequest({
		// apiTest.testStoreDetail({
			"url" : App.serverUrl+"/app/shop/getShopDetail.do",
			"params" : {"shopId" : pageVariables.shopId},
			"success" : function(result){
				if(result.success.toString() == "true"){//success
					pageVariables.shop = result.resultObject;

					//查询微信账户
			        CommonUtil.sendJsonpRequest({
			        // apiTest.testGetAccount({
			        	"url" : App.serverUrl+"/app/wxAccount/getShopAccount.do",
			        	"params" : {"shopId" : pageVariables.shopId , "merchantId" : pageVariables.shop.merchantId},
			        	"success" : function(result){
			        		if(result.success.toString() == "true"){//success

			        			pageVariables.weixinAccount = result.resultObject;
			        			CommonUtil.render($("#weixinChangePage .page-body"), "weixinChangeTPL",{"data":result.resultObject,"utils":{"extractFilePath" : extractFilePath},"constants" : $.extend(Constants,{"previewUrlPrefix" : App.previewUrlPrefix})},false);
								// alert($("#weixinChangePage li[name='frontPicture']").attr("uploadType"));
			        			//控制图片显示
			        			displayPicture($("#weixinChangePage li[name='frontPicture']"),"show");
			        			displayPicture($("#weixinChangePage li[name='backPicture']"),"show");

								//开户行地区
								init4BankDistrict(function(){
									$("#weixinChangePage div[name='bankDistrict']>ul").mobiscroll("setArrayVal",[pageVariables.weixinAccount.provinceName,pageVariables.weixinAccount.cityName],true);
									$("#weixinChangePage div[name='bankDistrict']>input[type='hidden']").val(pageVariables.weixinAccount.province+","+pageVariables.weixinAccount.city);

									//开户主银行
									init4AccountMainBank(function(){
										$("#weixinChangePage div[name='mainBank']>ul").mobiscroll("setVal",pageVariables.weixinAccount.bankMainName,true);
										$("#weixinChangePage div[name='mainBank']>input[type='hidden']").val(pageVariables.weixinAccount.bankId);
									});
								});

			        		}else{//business error
			        			DialogUtil.dialogWarn(result.msg);
			        		}
			        	},
			        	"error" : function(){//not 200
			        		DialogUtil.dialogWarn("请求失败，请稍候重试");
			        	}
			        });

				}else{//business error
					DialogUtil.dialogWarn(result.msg);
				}
			},
			"error" : function(){//not 200
				DialogUtil.dialogWarn("请求失败，请稍候重试");
			}
		});
	}

	//提取图片地址path（老数据带域名）
	function extractFilePath(path){
		if(/^http/.test(path)){
			path = path.replace(App.previewUrlPrefix,"");
		}
		return path;
	}

	//开户行地区
	function init4BankDistrict(callback){

		CityUtil.getProvinceCityHtml(function(ul){
	    	$("#weixinChangePage div[name='bankDistrict']").prepend(ul);
	    	$("#weixinChangePage div[name='bankDistrict']>ul").mobiscroll().treelist({
	            "theme": "ios",
	            "display": "bottom",
	            "lang": "zh",
	            "placeholder": "请选择省、市",
	            "formatValue" : function(data){
	            	return data.join("-");
	            },
	            "onSelect" : function(valueText,inst){
	            	var codeArray = [];
	            	var $ul = $this = $(this);
	            	$.each(valueText.split("-"),function(index,value){
	            		var $li = $ul.children("li[data-val='"+value+"']");
	            		codeArray.push($li.attr("data-code"));  //data会进行类型转换
	            		$ul = $li.children("ul").eq(0);
	            	});
	            	$this.parent().find("input[type='hidden']").val(codeArray.join(","));

	            	//清空级联数据
	            	init4AccountMainBank(function(){
	            	});
	            	$("#weixinChangePage input[name='branchBank']").val("");
	            	$("#weixinChangePage input[name='contactLine']").val("");

	            	listen4Submit();
	        	}
	    	});

	    	//组件初始化后回调
	    	callback();
	    });

        
	}

	//开户主银行
	function init4AccountMainBank(callback){

		var accountBankDistrict = $("#weixinChangePage div[name='bankDistrict']>input[type='hidden']").val();
		var provinceCode = accountBankDistrict.split(",")[0];
		var cityCode = accountBankDistrict.split(",")[1];

        CommonUtil.sendJsonpRequest({
        // apiTest.testGetBankList({
        	"url" : App.serverUrl+"/app/wxAccount/getBanks.do",
        	"params" : {"province" : provinceCode , "city" : cityCode},
        	"success" : function(result){
        		if(result.success.toString() == "true"){//success

        			//销毁组件
        			if($("#weixinChangePage div[name='mainBank']>ul").length > 0){
        				$("#weixinChangePage div[name='mainBank']>ul").mobiscroll("destroy");
        				$("#weixinChangePage div[name='mainBank']>ul").remove();
        				$("#weixinChangePage div[name='mainBank']>input[type='hidden']").val("");
        			}

        			//构建组件
        			var bankList = result.resultObject;
        			var bankListHtml = "<ul style='display:none;'>";
        			$.each(bankList,function(index,element){
        				bankListHtml += "<li data-code='"+element.bankCode+"' data-val='"+element.bankName+"'>"+element.bankName+"</li>";
        			});
        			bankListHtml += "</ul>";
        			$("#weixinChangePage div[name='mainBank']").prepend(bankListHtml);

					$("#weixinChangePage div[name='mainBank']>ul").mobiscroll().treelist({
			            "theme": "ios",
			            "display": "bottom",
			            "lang": "zh",
			            "placeholder": "请选择",
			            "onSelect" : function(valueText,inst){
			            	var codeArray = [];
			            	var $ul = $this = $(this);
			            	$.each(valueText.split("-"),function(index,value){
			            		var $li = $ul.children("li[data-val='"+value+"']");
			            		codeArray.push($li.attr("data-code"));  //data会进行类型转换
			            		$ul = $li.children("ul").eq(0);
			            	});
			            	$this.parent().find("input[type='hidden']").val(codeArray.join(","));

			            	//清空级联数据
			            	$("#weixinChangePage input[name='branchBank']").val("");
			            	$("#weixinChangePage input[name='contactLine']").val("");

			            	listen4Submit();
			            }
			        });

			        //组件初始化后回调
			        callback();

        		}else{//business error
        			DialogUtil.dialogWarn(result.msg);
        		}
        	},
        	"error" : function(){//not 200
        		DialogUtil.dialogWarn("请求失败，请稍候重试");
        	}
        });
	}

	//校验返回
	function confirm4Back(){

		var bankDistrict = $("#weixinChangePage div[name='bankDistrict']>input[type='hidden']").val();		//开户行地区
		var mainBank = $("#weixinChangePage div[name='mainBank']>input[type='hidden']").val();		//开户银行
		var branchBank = $("#weixinChangePage input[name='branchBank']").val();		//支行名称
		var contactLine = $("#weixinChangePage input[name='contactLine']").val().trim();	//联行号
		var bankAccount = $("#weixinChangePage input[name='bankAccount']").val().trim();		//银行帐号
		var mobile = $("#weixinChangePage input[name='mobile']").val().trim();	//手机号
		var identityCard = $("#weixinChangePage input[name='identityCard']").val();	//身份证
		var weixinImgUrl4Front = $("#weixinChangePage li[name='frontPicture']").attr("weixinImgUrl"); //正面：微信
		var weixinImgUrl4Back = $("#weixinChangePage li[name='backPicture']").attr("weixinImgUrl"); //反面：微信

		//没有修改任何表单
		if(
			bankDistrict == (pageVariables.weixinAccount.province + "," + pageVariables.weixinAccount.city)
			&& (mainBank == pageVariables.weixinAccount.bankId) 
			&& (branchBank == pageVariables.weixinAccount.bankName) 
			&& (contactLine == pageVariables.weixinAccount.contactLine) 
			&& (bankAccount == pageVariables.weixinAccount.accountCode) 
			&& (mobile == pageVariables.weixinAccount.tel) 
			&& (identityCard == pageVariables.weixinAccount.idCard) 
			&& (weixinImgUrl4Front == pageVariables.weixinAccount.identityCardPicFront) 
			&& (weixinImgUrl4Back == pageVariables.weixinAccount.identityCardPicContrary) 
		){
			if(pageVariables.weixinAccount.accountType == Constants.weixin.ACCOUNT_TYPE.person){//个人账户
				var username4Person = $("#weixinChangePage input[name='username4Person']").val().trim();	//开户人姓名
				if(username4Person == pageVariables.weixinAccount.accountName){
					$.router.back();
					return;
				}

			}else if(pageVariables.weixinAccount.accountType == Constants.weixin.ACCOUNT_TYPE.company){//公司账户
				var companyName4Company = $("#weixinChangePage input[name='companyName4Company']").val().trim();	//收款单位
				var pricipal4Company = $("#weixinChangePage input[name='principal4Company']").val().trim();	//负责人
				if(companyName4Company == pageVariables.weixinAccount.accountName && pricipal4Company == pageVariables.weixinAccount.principal){
					$.router.back();
					return;
				}
			}
		}

		//已修改：需要确认是否放弃
		DialogUtil.dialogConfirm({
			"title" : "",
			"content" : "离开页面将不会保存本次修改，确定要离开吗？",
			"btnLeft" : "取消",
			"btnRight" : "确定",
			"callbackLeft" : function(){},
			"callbackRight" : function(){
				$.router.back();
			}
		});

		
	}

	//控制“下一步”是否可点击
	function listen4Submit(){

		var bankDistrict = $("#weixinChangePage div[name='bankDistrict'] input[type='hidden']").val();	//开户行所在地区
		var mainBank = $("#weixinChangePage div[name='mainBank'] input[type='hidden']").val();	//开户行编码
		var branchBank = $("#weixinChangePage input[name='branchBank']").val();	//支行名称
		var contactLine = $("#weixinChangePage input[name='contactLine']").val();	//联行号
		var bankAccount = $("#weixinChangePage input[name='bankAccount']").val();	//银行帐号
		var mobile = $("#weixinChangePage input[name='mobile']").val();	//手机号
		var identityCard = $("#weixinChangePage input[name='identityCard']").val();	//身份证
		var weixinImgUrl4Front = $("#weixinChangePage li[name='frontPicture']").attr("weixinImgUrl"); //正面：微信
		var weixinImgUrl4Back = $("#weixinChangePage li[name='backPicture']").attr("weixinImgUrl"); //反面：微信

		if(bankDistrict && mainBank && branchBank && contactLine && bankAccount && mobile && identityCard && weixinImgUrl4Front && weixinImgUrl4Back){
			if(pageVariables.weixinAccount.accountType == Constants.weixin.ACCOUNT_TYPE.person){
				var username4Person = $("#weixinChangePage input[name='username4Person']").val();	//开户人姓名
				if(username4Person){
					$("#weixinChangePage .header li.right").removeClass("disabled");
					return;
				}
			}else if(pageVariables.weixinAccount.accountType == Constants.weixin.ACCOUNT_TYPE.company){
				var companyName4Company = $("#weixinChangePage input[name='companyName4Company']").val();	//收款单位
				var pricipal4Company = $("#weixinChangePage input[name='principal4Company']").val();	//负责人
				if(companyName4Company && pricipal4Company){
					$("#weixinChangePage .header li.right").removeClass("disabled");
					return;
				}
			}
		}

		$("#weixinChangePage .header li.right").addClass("disabled");
	}

	//页面事件绑定
	function bindEvent4Page(){

		//监听输入，控制下一步是否可点击
		var listenFormStr = "#weixinChangePage input[name='contactLine']," + 
							"#weixinChangePage input[name='bankAccount']," + 
							"#weixinChangePage input[name='username4Person']," + 
							"#weixinChangePage input[name='companyName4Company']," + 
							"#weixinChangePage input[name='principal4Company']," + 
							"#weixinChangePage input[name='mobile']," + 
							"#weixinChangePage input[name='identityCard']";
		$(document).on("input",listenFormStr,function(e){
			listen4Submit();
		});
		$(document).on("clearInput","#weixinChangePage .zhk-list_gb",function(e){
			listen4Submit();
		});

		//返回
		$(document).on("click","#weixinChangePage .header a.back",function(e){
			confirm4Back();
		});

		//支行名称
		$(document).on("click","#weixinChangePage input[name='branchBank']",function(e){
			var bankDistrict = $("#weixinChangePage div[name='bankDistrict'] input[type='hidden']").val();
			if(!bankDistrict){
				DialogUtil.dialogWarn("请您先选择开户行地区");
				return;
			}

			var mainBank = $("#weixinChangePage div[name='mainBank'] input[type='hidden']").val();
			if(!mainBank){
				DialogUtil.dialogWarn("请您先选择开户银行");
				return;
			}

			var cache = CommonUtil.takeOutParamObject() || {};
			cache.bankDistrict = bankDistrict;
			cache.mainBank = mainBank;
			CommonUtil.injectParamObject(cache);
			$.router.load("weixin_branch_bank_search.html",true);
		});

		//身份证照片
		$(document).on("click","#weixinChangePage input[type='file']",function(e){//阻止file默认行为
			e.preventDefault();
		});	
		$(document).on("click","#weixinChangePage li.picture",function(e){//上传
			if($(e.target).hasClass("zhk-list_gb"))	return;

			uploadPicture($(this));
		});	
		$(document).on("click","#weixinChangePage .picture .zhk-list_gb",function(e){//删除
			var $li = $(this).parents("li.picture");
			displayPicture($li,"hide");

			$li.attr("yzImgUrl","");
			$li.attr("weixinImgUrl","");

			listen4Submit();
		});


		//提交
		$(document).on("click","#weixinChangePage .header a[name='submit']",function(e){
			if($(this).parents(".right").hasClass("disabled"))	return;

			submitWeixinChange();
		});
		
	}

	//身份证显示
	function displayPicture(target,showOrHide){

		if(showOrHide == "show"){
			target.find("div.upload-before").hide();
			target.find("div.upload-after").show();
		}else if(showOrHide == "hide"){
			target.find("div.upload-before").show();
			target.find("div.upload-after").hide();
		}
	}

	//上传身份证照片
	function uploadPicture(target){

		$.actions([[{
			"text" : "相册",
			"onClick" : function(){

				//选择
				AppUtil.call(AppUtil.APIS.SELECT_PICTURE,{"compress":{"sizeLimit":"500","unit":"K"},"format":"JPG","maxNum":"1"},function(selectResult){
					if(selectResult.success.toString() == "true"){
						var filePath = selectResult.resultObject[0];

						//上传
						common.loading("上传中");
						AppUtil.call(AppUtil.APIS.UPLOAD_PICTURE,{"url":App.serverUrl+"/app/img/upload.do","file":filePath,"data":{"shopId":pageVariables.shopId,"uploadType":target.attr("uploadType")}},function(uploadResult){
							common.closeLoading();
							if(uploadResult.success.toString() == "true" && uploadResult.resultObject.success.toString() == "true"){
								target.attr("yzImgUrl",uploadResult.resultObject.resultObject.imageUrl);
								target.attr("weixinImgUrl",uploadResult.resultObject.resultObject.thirdPartyImageUrl);

								//显示图片
								target.find("img").attr("src",filePath);
								displayPicture(target,"show");

								listen4Submit();
							}else{
								var msg = "";
								if(uploadResult.success.toString() == "false"){
									msg = uploadResult.msg;
								}else if(uploadResult.resultObject.success.toString() == "false"){
									msg = uploadResult.resultObject.msg;
								}
								DialogUtil.dialogWarn(msg);
							}
						});
					}else{
						DialogUtil.dialogWarn(selectResult.msg);
					}
				})
			}
		},{
			"text" : "拍照",
			"onClick" : function(){

				//拍照
				AppUtil.call(AppUtil.APIS.TAKE_PICTURE,{"compress":{"sizeLimit":"500","unit":"K"},"format":"JPG","maxNum":"1"},function(selectResult){
					if(selectResult.success.toString() == "true"){
						var filePath = selectResult.resultObject;

						//上传
						common.loading("上传中");
						AppUtil.call(AppUtil.APIS.UPLOAD_PICTURE,{"url":App.serverUrl+"/app/img/upload.do","file":filePath,"data":{"shopId":pageVariables.shopId,"uploadType":target.attr("uploadType")}},function(uploadResult){
							common.closeLoading();
							if(uploadResult.success.toString() == "true" && uploadResult.resultObject.success.toString() == "true"){
								target.attr("yzImgUrl",uploadResult.resultObject.resultObject.imageUrl);
								target.attr("weixinImgUrl",uploadResult.resultObject.resultObject.thirdPartyImageUrl);

								//显示图片
								target.find("img").attr("src",filePath);
								displayPicture(target,"show");

								listen4Submit();
							}else{
								var msg = "";
								if(uploadResult.success.toString() == "false"){
									msg = uploadResult.msg;
								}else if(uploadResult.resultObject.success.toString() == "false"){
									msg = uploadResult.resultObject.msg;
								}
								DialogUtil.dialogWarn(msg);
							}
						});
					}else{
						DialogUtil.dialogWarn(selectResult.msg);
					}
				})
			}
		}],[{
			"text" : "取消",
			"color" : "danger",
			"onClick" : function(){
			}
		}]]);

	}


	//提交微信变更
	function submitWeixinChange(){

		//表单参数
		var bankDistrict = $("#weixinChangePage div[name='bankDistrict']>input[type='hidden']").val();		//开户行地区
		var bankDistrictText = $("#weixinChangePage div[name='bankDistrict']>ul").mobiscroll("getArrayVal");
		var mainBank = $("#weixinChangePage div[name='mainBank']>input[type='hidden']").val();		//开户银行
		var mainBankText = $("#weixinChangePage div[name='mainBank']>ul").mobiscroll("getVal");
		var branchBank = $("#weixinChangePage input[name='branchBank']").val();		//支行名称
		var contactLine = $("#weixinChangePage input[name='contactLine']").val().trim();	//联行号
		var bankAccount = $("#weixinChangePage input[name='bankAccount']").val().trim();		//银行帐号
		var username4Person = "";	//开户人姓名
		var companyName4Company = "";	//收款单位
		var pricipal4Company = "";	//负责人
		var mobile = $("#weixinChangePage input[name='mobile']").val().trim();	//手机号
		var identityCard = $("#weixinChangePage input[name='identityCard']").val().trim();	//身份证
		var yzImgUrl4Front = $("#weixinChangePage li[name='frontPicture']").attr("yzImgUrl"); //正面：云纵
		var weixinImgUrl4Front = $("#weixinChangePage li[name='frontPicture']").attr("weixinImgUrl"); //正面：微信
		var yzImgUrl4Back = $("#weixinChangePage li[name='backPicture']").attr("yzImgUrl");	//反面：云纵
		var weixinImgUrl4Back = $("#weixinChangePage li[name='backPicture']").attr("weixinImgUrl"); //反面：微信

		//校验：开户行地区
		if(!bankDistrict){
			DialogUtil.dialogWarn("请选择开户行地区");
			return;
		}

		//校验：开户银行
		if(!mainBank){
			DialogUtil.dialogWarn("请选择开户银行");
			return;
		}

		//校验：支行名称
		if(!branchBank){
			DialogUtil.dialogWarn("请选择支行名称");
			return;
		}

		//校验：联行号
		if(contactLine.length == 0){
			DialogUtil.dialogWarn("请填写联行号");
			return;
		}
		if(!/^\d{12}$/.test(contactLine)){
			DialogUtil.dialogWarn("联行号必须为12位数字");
			return;
		}

		//校验：银行帐号
		if(bankAccount.length == 0){
			DialogUtil.dialogWarn("请填写银行账号");
			return;
		}
		if(!/^\d{1,32}$/.test(bankAccount)){
			DialogUtil.dialogWarn("请填写有效的银行账号");
			return;
		}

		if(pageVariables.weixinAccount.accountType == Constants.weixin.ACCOUNT_TYPE.person){//个人

			//校验：开户人姓名
			username4Person = $("#weixinChangePage input[name='username4Person']").val().trim();
			if(username4Person.length == 0){
				DialogUtil.dialogWarn("请填写开户人姓名");
				return;
			}
			if(!/^[\u4e00-\u9fa5]+$/.test(username4Person)){
				DialogUtil.dialogWarn("开户人姓名仅允许输入中文");
				return;
			}
			if(username4Person.length > 32){
				DialogUtil.dialogWarn("开户人姓名长度不能大于32");
				return;
			}

		}else if(pageVariables.weixinAccount.accountType == Constants.weixin.ACCOUNT_TYPE.company){//企业
			
			//校验：收款单位
			companyName4Company = $("#weixinChangePage input[name='companyName4Company']").val().trim();
			if(companyName4Company.length == 0){
				DialogUtil.dialogWarn("请填写收款单位");
				return;
			}
			if(!/^[\u4e00-\u9fa5]+$/.test(companyName4Company)){
				DialogUtil.dialogWarn("收款单位仅允许输入中文");
				return;
			}
			if(companyName4Company.length > 32){
				DialogUtil.dialogWarn("收款单位长度不能大于32");
				return;
			}

			//校验：负责人
			pricipal4Company = $("#weixinChangePage input[name='principal4Company']").val().trim();
			if(pricipal4Company.length == 0){
				DialogUtil.dialogWarn("请填写负责人姓名");
				return;
			}
			if(!/^[\dA-Za-z\u4e00-\u9fa5]+$/.test(pricipal4Company)){
				DialogUtil.dialogWarn("收款单位仅允许输入中文、英文、数字");
				return;
			}
			if(pricipal4Company.length > 32){
				DialogUtil.dialogWarn("负责人长度不能大于32");
				return;
			}
		}

		//校验：手机号
		if(mobile.length == 0){
			DialogUtil.dialogWarn("请填写手机号");
			return;
		}
		if(!/^[1][3578][0-9]{9}$/.test(mobile)){
			DialogUtil.dialogWarn("请填写有效的手机号");
			return;
		}

		//校验：身份证号码
		if(identityCard.length == 0){
			DialogUtil.dialogWarn("请填写身份证号码");
			return;
		}
		if(!/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/.test(identityCard) && !/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/.test(identityCard)){
			DialogUtil.dialogWarn("请填写有效的身份证号码");
			return;
		}

		//校验：身份证照片
		if(!yzImgUrl4Front){
			DialogUtil.dialogWarn("请上传正面身份证");
			return;
		}
		if(!yzImgUrl4Back){
			DialogUtil.dialogWarn("请上传反面身份证");
			return;
		}

		//提交
		var stepTwo = {};
		stepTwo.shopId = pageVariables.shopId;		//门店Id
		stepTwo.accountType = pageVariables.weixinAccount.accountType; //账户类型
		stepTwo.accountTypeName = Constants.weixin.getAccountTypeText(pageVariables.weixinAccount.accountType);
		stepTwo.bankProvince = bankDistrict.split(",")[0]; //开户行所在省份
		stepTwo.bankProvinceName = bankDistrictText[0];
		stepTwo.bankCity = bankDistrict.split(",")[1]; //开户行所在市
		stepTwo.bankCityName = bankDistrictText[1];
		stepTwo.bankId = mainBank; //主行编码
		stepTwo.bankMainName = mainBankText;
		stepTwo.bankName = branchBank; //支行名称
		stepTwo.accountCode = bankAccount; //银行账号
		stepTwo.contactLine = contactLine; //联行号
		if(pageVariables.weixinAccount.accountType == Constants.weixin.ACCOUNT_TYPE.person){
			stepTwo.accountName = username4Person;//开户人姓名
			stepTwo.principal = username4Person;
		}else if(pageVariables.weixinAccount.accountType == Constants.weixin.ACCOUNT_TYPE.company){
			stepTwo.accountName = companyName4Company;//收款单位
			stepTwo.principal = pricipal4Company; //负责人
		}
		stepTwo.principalMobile = mobile; //手机号
		stepTwo.idCard = identityCard; //身份证号码
		stepTwo.merchantId = pageVariables.shop.merchantId; //微信支付商户号
		stepTwo.yzImageFrontUrl = yzImgUrl4Front; //正面：云纵
		stepTwo.identityCardPicFront = weixinImgUrl4Front; //正面：微信
		stepTwo.yzImageReverseUrl = yzImgUrl4Back; //反面：云纵
		stepTwo.identityCardPicContrary = weixinImgUrl4Back; //反面：微信

		common.loading("提交中");
		AppUtil.call(
		// apiTest.testSubmit(
			AppUtil.APIS.SEND_HTTP_REQUEST,
			{
				"type":"POST",
				"url":App.serverUrl+"/app/wxAccount/change.do",
				"data" : JSON.stringify(stepTwo)
			},
			function(result){
				common.closeLoading();
				
				var cache = CommonUtil.takeOutParamObject() || {};
				cache.shopId = pageVariables.shopId;
				CommonUtil.injectParamObject(cache);

				if(result.success.toString() == "true" && result.resultObject.success.toString() == "true"){//success
					$.router.load("weixin_change_success.html");
				}else{
					var errorMsg = "";
					if(result.success.toString() == "false"){//app error
						errorMsg = result.msg;
					}else if(result.resultObject.success.toString() == "false"){//server error
						errorMsg = result.resultObject.msg;
					}
					
					var cache = CommonUtil.takeOutParamObject() || {};
					cache.errorMsg = errorMsg;
					CommonUtil.injectParamObject(cache);
					$.router.load("weixin_change_error.html");
				}
			}
		);
	}

	/**
	 * 测试接口
	 * @type {Object}
	 */
	var apiTest = {

		"testStoreDetail" : function(options){
			options.success({
				"success" : true,
				"resultObject" : {
					"shopId" : "1",
					"mainShopName" : "麦当劳",
					"branchShopName" : "上地南路店",
					"categoryLevel1" : "美食",
					"categoryLevel2" : "西餐",
					"categoryLevel3" : "快餐",
					"contactNumber" : "11111111111",
					"address" : "北京市海淀区上地南路88号",
					"isOnline" : "T", //口碑门店状态 T ：上架 F：下架
					"serviceVersionType" : "1",	//订购版本 0：未订购 1：金元宝 2：银元宝 3：快享付
					"proUpgradeStatus" : "1", //订购状态 0：未订购 1：正常 2：已退订 3：已过期
					"expireDate" : "2017-05-08 12:12:12",	
					"alipayPayStatus" : "1", //支付宝开通状态 0：未开通 1：已开通
					"merchantStatus" : "1", //微信开通状态 0：未开通 1：已开通 2：已冻结
					"merchantId" : "001", //微信支付商户号
				}
				
			});
		},

		"testGetAccount" : function(options){//查询微信账户
			options.success({
				"success" : true,
				"resultObject" : {
					"accountType" : "1" , //1:企业 ;2:个人
					"province" : "170000",
					"provinceName" : "湖北省",
					"city" : "170100",
					"cityName" : "武汉市",
					"bankId" : "002",
					"bankMainName" : "中国工商银行",
					"bankName" : "上地支行",
					"accountCode" : "6228480000000000000",
					"contactLine" : "999999",
					"accountName" : "张三", //开户人姓名/收款单位
					"principal" : "李总",
					"tel" : "18611111111",
					"idCard" : "42128119999999999X",//身份证
					"yzImageFrontUrl" : "http://oqv5rpmht.bkt.clouddn.com/test.jpg", //正面：云纵
					"identityCardPicFront" : "http://oqv5rpmht.bkt.clouddn.com/test.jpg", //正面：微信
					"yzImageReverseUrl" : "http://oqv5rpmht.bkt.clouddn.com/test.jpg" , //反面：云纵
					"identityCardPicContrary" : "http://oqv5rpmht.bkt.clouddn.com/test.jpg" //反面：微信
				}
			});
		},

		"testGetBankList" : function(options){//获取开户银行列表
			options.success({
				"success" : true,
				"resultObject" : [
					{"bankCode" : "001" , "bankName" : "中国银行"},
					{"bankCode" : "002" , "bankName" : "中国工商银行"},
					{"bankCode" : "003" , "bankName" : "中国建设银行"},
					{"bankCode" : "004" , "bankName" : "中国农业银行"}
				]
			});
		},

		"testSubmit" : function(apiName,params,callback){//提交变更
			callback({
				"code" : "0",
				"msg" : "",
				"resultObject" : {
					"code" : "0",
					"msg" : "",
					"success" : true,
					"resultObject" : ""
				},
				"success" : true
			});
		}
	};

})(document, window);